package com.java.action;

import java.util.List;

import com.java.pojo.ComDept;
import com.java.pojo.ComEmp;
import com.java.service.IEmpService;

public class EmpSearchAction {

	private static final int PAGEROW = 5;
	private IEmpService empService;
	private String EName;
	private String EPhone;
	private Integer EDeptno;
	private String EJob;
	private List<ComEmp> list;
	private int page=1;
	private int currentPage;
	private int totalPages;
	private List<ComDept> dept;
	private int rowCount;
	
	public int getRowCount() {
		return rowCount;
	}

	public void setRowCount(int rowCount) {
		this.rowCount = rowCount;
	}

	public String execute() {

		System.out.println("page: " + page);
		System.out.println("execute.....");
		rowCount = empService.getEmpNum(EName, EPhone, EDeptno, EJob);
		System.out.println("rowCount:" + rowCount);
		totalPages = (rowCount % PAGEROW == 0) ? (rowCount / PAGEROW)
				: (rowCount / PAGEROW + 1);
		if (page < 1) {
			page = 1;
		}
		if (page > totalPages) {
			page = totalPages;
		}
		int start = (page - 1) * PAGEROW;
		System.out.println("start: " + start);
		currentPage = page;
		System.out.println(EName + "|" + EPhone +"|" + EDeptno +"|" + EJob);
		list = empService.getEmpListByConditions(EName, EPhone, EDeptno, EJob,
				start, PAGEROW);
		
		dept = empService.getDeptno();
		System.out.println("dept: " + dept.toString());
		return "success";
	}

	public List<ComEmp> getList() {
		return list;
	}

	public void setList(List<ComEmp> list) {
		this.list = list;
	}

	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}

	public int getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}

	public int getTotalPages() {
		return totalPages;
	}

	public void setTotalPages(int totalPages) {
		this.totalPages = totalPages;
	}

	public static int getPagerow() {
		return PAGEROW;
	}

	public IEmpService getEmpService() {
		return empService;
	}

	public void setEmpService(IEmpService empService) {
		this.empService = empService;
	}

	public String getEName() {
		return EName;
	}

	public void setEName(String eName) {
		EName = eName;
	}

	public String getEPhone() {
		return EPhone;
	}

	public void setEPhone(String ePhone) {
		EPhone = ePhone;
	}

	public Integer getEDeptno() {
		return EDeptno;
	}

	public void setEDeptno(Integer eDeptno) {
		EDeptno = eDeptno;
	}

	public String getEJob() {
		return EJob;
	}

	public void setEJob(String eJob) {
		EJob = eJob;
	}

	public List<ComDept> getDept() {
		return dept;
	}

	public void setDept(List<ComDept> dept) {
		this.dept = dept;
	}

	
}
